function t(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

var a = t(require("../../../utils/filter")), e = t(require("../../../api/api")), o = t(require("../../../utils/util")), u = getApp();

Page({
    data: {
        pageNum: 1,
        pageSize: 9,
        hasMore: !0,
        itc_usd_value: "",
        couponParams: {},
        content_list: []
    },
    onLoad: function(t) {
        var a = getCurrentPages();
        "pages/wallet/wallet" === a[1].route && 3 === a.length ? this.setData({
            couponFromWallet: !0
        }) : this.setData({
            couponFromWallet: !1
        });
        var e = t.itc;
        this.setData({
            itc_usd_value: e,
            couponParams: t
        }), this.fetchCouponList();
    },
    fetchCouponList: function() {
        var t = this, a = this, o = {
            page: a.data.pageNum,
            available: 1,
            use_type: -1,
            page_size: 9
        };
        this.data.couponFromWallet || (o = Object.assign(o, this.data.couponParams)), e.default.couponList({
            data: o,
            success: function(e) {
                var o = a.data.content_list;
                if (e && e.data) {
                    1 == a.data.pageNum && (o = []);
                    var u = e.data.data.coupon_list;
                    u.forEach(t.mergeCouponHistoryInfo), u.length < a.data.pageSize ? t.setData({
                        content_list: o.concat(u),
                        hasMore: !1
                    }) : t.setData({
                        content_list: o.concat(u),
                        hasMore: !0,
                        pageNum: a.data.pageNum + 1
                    });
                }
            }
        });
    },
    mergeCouponHistoryInfo: function(t) {
        t.start_date_format = o.default.formatCurrentDate(t.start_time), t.end_date_format = o.default.formatCurrentDate(t.end_time), 
        t.coupon_value_usd = t.voucher_value / 100, t.coupon_value_cny = a.default.convertCurrencyToCNY(t.voucher_value, u.globalData.currencyDatum), 
        this.data.couponFromWallet || (t.is_disabled = !(this.data.itc_usd_value >= t.use_limit_itc));
    },
    onReachBottom: function(t) {
        var a = this;
        a.data.hasMore && a.fetchCouponList();
    },
    useThisCoupon: function(t) {
        var a = t.currentTarget.id;
        this.data.itc_usd_value >= this.data.content_list[a].use_limit_itc && (this.setData({
            activeIndex: t.currentTarget.id,
            selectedCoupon: this.data.content_list[a]
        }), u.globalData.selectedCoupon = this.data.selectedCoupon, wx.navigateBack({
            delta: 1
        }));
    },
    cancelCoupon: function() {
        this.setData({
            activeIndex: null,
            selectedCoupon: null
        }), u.globalData.selectedCoupon = "", wx.navigateBack({
            delta: 1
        });
    }
});